home *** CD-ROM | disk | FTP | other *** search
- Path: news.uni-stuttgart.de!schweikh
- From: schweikh@itosun.ito.uni-stuttgart.de (Jens Schweikhardt)
- Newsgroups: comp.lang.c
- Subject: Re: hex to dec function?
- Date: 26 Feb 1996 13:15:50 GMT
- Organization: Comp.Center (RUS), U of Stuttgart, FRG
- Message-ID: <4gsbq6$2dce@info4.rus.uni-stuttgart.de>
- References: <4gdh1b$bg@mailhost.mwmicro.com> <larry_kearney-2302960806460001@amaryllisp1.appsig.com>
- NNTP-Posting-Host: itosun.ito.uni-stuttgart.de
-
- In article <larry_kearney-2302960806460001@amaryllisp1.appsig.com>,
- Larry Kearney <larry_kearney@appsig.com> wrote:
- >In article <4gdh1b$bg@mailhost.mwmicro.com>, aschlies@citynet.net wrote:
- >> Hi There,
- >> Is there a function that converts HEX to Dec in ANSI C?
- >> Why re-invent the wheel?
- >> Thanks Tony
- >
- >I assume you mean convert a character string containing hex digits
- >('A'-'F','0'-'9') into a decimal integer. If so, use
- > unsigned int int_value;
- > unsigned long int long_int_value;
- > char *string_buffer;
- > ...
-
- I hope the ... means 'have a string_buffer = malloc (somesize);' here.
- And don't forget to put your hex string there.
-
- > sscanf( string_buffer, "%x", int_value );
- > sscanf( string_buffer, "%lx", long_int_value );
-
- At the risk of stating the obvious, my workstation will probably
- dump core because sscanf wants _pointers_ to int_value and
- long_int_value, i.e. &int_value.
- Please please please _test_compile_ any answers you give before posting.
- And run them. Even more so, don't post bogus code.
-
- Thanks for your cooperation.
-
- Bye, Jens
- --
- SIGSIG -- signature too long (core dumped)
-